<template>
    <div class="count">
        <h2>当前求和为：{{sum}}</h2>
        <h2>x10为：{{ bigSum }}</h2>
        <h2>欢迎来到{{ address }},大写{{ upperAddress }}</h2>
        <select v-model="n">
            <option :value="1">1</option>
            <option :value="2">2</option>
            <option :value="3">3</option>
        </select>
        <button @click="add">+</button>
        <button @click="minus">-</button>
    </div>
</template>

<script setup lang="ts" name="Count">
    import { ref ,toRefs} from 'vue'
    import {useCountStore} from '@/store/count'
    import { storeToRefs } from 'pinia';
    const countStore = useCountStore()
    // toRef会将所有对象都变成ref，不建议
    // const {sum,address} = toRefs(countStore)

    // storeToRefs只关注store中的数据，不会对方法进行ref包裹
    const {sum,address,bigSum,upperAddress} = storeToRefs(countStore)



    //let sum = ref(0)
    let n = ref(1)
    function add(){
        // 修改数据的三个方法
        // 一：
        // countStore.sum += n.value

        // 二：
        // countStore.$patch({
        //     sum:888,
        //     address:'JN'
        // })

        // 三:
        countStore.add_store(n.value)
    }
    function minus(){
        // sum.value -= n.value
        countStore.minus_store(n.value)
    }

</script>

<style scoped>
.count{
    background-color: skyblue;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
}
select,button{
    margin: 0 5px;
    height: 25px;
}
</style>